<?php echo script_tag('public/js/tiny_mce/tiny_mce.js'); ?>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "exact",
		elements: 'mainbody',
		theme : "advanced",
		plugins : "table,inlinepopups,codeprotect",
		height: '300',
		width: "780",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		apply_source_formatting : false,

		// Example content CSS (should be your site CSS)
		content_css : "<?php echo site_url('public/css/content.css'); ?>",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		formats : {
			alignleft : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'left'},
			aligncenter : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'center'},
			alignright : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'right'},
			alignfull : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'full'},
			bold : {inline : 'span', 'classes' : 'bold'},
			italic : {inline : 'span', 'classes' : 'italic'},
			underline : {inline : 'span', 'classes' : 'underline', exact : true},
			strikethrough : {inline : 'del'},
			customformat : {inline : 'span', styles : {color : '#00ff00', fontSize : '20px'}, attributes : {title : 'My custom format'}}
		}
	});
	
	$('form').submit(function() {
		if ($('textarea[name="content"]').is(':hidden'))
		{
			tinyMCE.get("mainbody").save();
		}
	});
	
	$(function() {
		var id = 'mainbody'; // ID of your textarea (no # symbol) 
		$("span.toggle").toggle(function(){
				tinyMCE.execCommand('mceRemoveControl', false, id);
				var str = $('#' + id).val();
				$('#' + id).val(stripHtml(str));
			}, function () {
			tinyMCE.execCommand('mceAddControl', false, id);
		});
	});
	
	function stripHtml(str){
		return str.replace(/<\S[^><]*>/gi, "");
	}
</script>